package com.myadapter;

import java.util.ArrayList;

import com.bean.feeds;
import com.example.lizhiinformation.R;
import com.tools.ImageLoader;
import com.tools.Path_URL;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FragmentAllAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<feeds> list;
	LayoutInflater inflater;
	private View view;

	public FragmentAllAdapter(Context context, ArrayList<feeds> list, View view) {
		super();
		this.context = context;
		this.list = list;
		this.view = view;
		inflater = LayoutInflater.from(context);
	}

	public void addData(ArrayList<feeds> List) {
		this.list.addAll(List);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public String getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0 - 2).getOid();
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		ViewHolde holder;
		if (arg1 == null) {
			holder = new ViewHolde();
			arg1 = inflater.inflate(R.layout.fragment_all_items, null);
			holder.imageView = (ImageView) arg1
					.findViewById(R.id.fragment_all_imageview1);
			holder.textViewtitle = (TextView) arg1
					.findViewById(R.id.fragment_all_textView1);
			holder.content = (TextView) arg1
					.findViewById(R.id.fragment_all_textView2);
			arg1.setTag(holder);
		} else {
			holder = (ViewHolde) arg1.getTag();
		}
		holder.textViewtitle.setText(list.get(arg0).getDataAll().getSubject());
		holder.content.setText(list.get(arg0).getDataAll().getSummary());
		ImageLoader.cachr(context, Path_URL.IMAGEURL
				+ list.get(arg0).getDataAll().getCover(), holder.imageView,
				view);
		return arg1;
	}

	class ViewHolde {
		private ImageView imageView;
		private TextView textViewtitle;
		private TextView content;
	}
}
